package com.ssm.controller;


import com.ssm.bean.Pool;
import com.ssm.service.PoolService;
import com.utils.Meg;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class PoolController {
    @Autowired
    private PoolService poolService;

    @RequestMapping("/poolView")
    public String poolView(){
        return "pool/pool";
    }

    @RequestMapping("/poolEditView")
    public String poolEditView(){
        return "pool/poolPage";
    }

    @RequestMapping("/poolAddView")
    public String poolAddView(){
        return "pool/poolAdd";
    }

    @ResponseBody
    @RequestMapping("/poolData")
    public Meg poolData(@Param("page") String page, @Param("limit") String limit){
        return Meg.success().add("data",poolService.selectAll(limit,page));
    }

    @ResponseBody
    @RequestMapping("/poolInsert")
    public Meg poolInsert(Pool pool){
        int i = poolService.insert(pool);
        if (i>0)
            return Meg.success();
        else
            return  Meg.file();
    }

    @ResponseBody
    @RequestMapping("/poolUpdate")
    public Meg poolUpdate(Pool pool){
        int i = poolService.update(pool);
        if (i>0)
            return Meg.success();
        else
            return  Meg.file();
    }

    @ResponseBody
    @RequestMapping("/poolDelete")
    public Meg poolDelete(@Param("id") Integer id){
        int i = poolService.delete(id);
        if (i>0)
            return Meg.success();
        else
            return  Meg.file();
    }

    @ResponseBody
    @RequestMapping("getPoolByToPk")
    public Meg getPoolByToPk(@RequestParam("toPk") Integer toPk){
        return Meg.success().add("data",poolService.getPoolByToPk(toPk));
    }
}
